<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>homework3</title>
</head>
<style>
    .bd{
        font-size: x-large;
    }
</style>
<body class="bd">
    <pre>
        import math

        location = {"x": 0, "y": 0}
        while 1:
            s = input()
            temp = s.split(" ")
            if s.__eq__("STOP"):
                break
            elif temp[0].__eq__("UP"):
                location["y"] = location["y"] + int(temp[1])
            elif temp[0].__eq__("DOWN"):
                location["y"] = location["y"] - int(temp[1])
            elif temp[0].__eq__("RIGHT"):
                location["x"] = location["x"] + int(temp[1])
            elif temp[0].__eq__("LEFT"):
                location["x"] = location["x"] - int(temp[1])

        print(round(math.sqrt(math.pow(location["x"], 2) + math.pow(location["y"], 2))))

    </pre>
</body>
</html>